no longer used
[phpmyadmin/crack.git] / libraries / plugin_interface.lib.php
blob97c054e389380fd1c66f62bd8ff8c35cfcb3e331
1 <?php
2 /* $Id$ */
3 // vim: expandtab sw=4 ts=4 sts=4:
5 /**
6 * Generic plugin interface.
7 */
9 /**
10 * array PMA_getPlugins(string $plugins_dir, mixed $plugin_param)
12 * Reads all plugin information from directory $plugins_dir.
14 * @uses ksort()
15 * @uses opendir()
16 * @uses readdir()
17 * @uses is_file()
18 * @uses eregi()
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)) {
28 $is_first = 0;
29 while ($file = @readdir($handle)) {
30 if (is_file($plugins_dir . $file) && eregi('\.php$', $file)) {
31 include $plugins_dir . $file;
35 ksort($plugin_list);
36 return $plugin_list;
39 /**
40 * string PMA_getString(string $name)
42 * returns locale string for $name or $name if no locale is found
44 * @uses $GLOBALS
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;
53 /**
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
58 * @uses $_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"';
72 return '';
75 /**
76 * string PMA_pluginGetDefault(string $section, string $opt)
78 * returns default value for option $opt
80 * @uses htmlspecialchars()
81 * @uses $_REQUEST
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])) {
94 return htmlspecialchars($GLOBALS['cfg'][$section][$opt]);
96 return '';
99 /**
100 * string PMA_pluginIsActive(string $section, string $opt, string $val)
102 * returns html input tag option 'checked' if option $opt should be set by config or request
104 * @uses $_REQUEST
105 * @uses $GLOBALS['cfg']
106 * @uses $GLOBALS['timeout_passed']
107 * @param string $section name of config section in
108 * $GLOBALS['cfg'][$section] for plugin
109 * @param string $opt name of option
110 * @param string $val value of option to check against
111 * @return string html input tag option 'checked'
113 function PMA_pluginIsActive($section, $opt, $val)
115 if ( ! empty($GLOBALS['timeout_passed']) && isset($_REQUEST[$opt])) {
116 if ($_REQUEST[$opt] == $val) {
117 return ' checked="checked"';
119 } elseif (isset($GLOBALS['cfg'][$section][$opt]) && $GLOBALS['cfg'][$section][$opt] == $val) {
120 return ' checked="checked"';
122 return '';
126 * string PMA_pluginGetChoice(string $section, string $name, array &$list)
128 * returns html radio form element for plugin choice
130 * @uses PMA_pluginIsActive()
131 * @uses PMA_getString()
132 * @param string $section name of config section in
133 * $GLOBALS['cfg'][$section] for plugin
134 * @param string $name name of radio element
135 * @param array &$list array with plugin configuration defined in plugin file
136 * @return string html input radio tag
138 function PMA_pluginGetChoice($section, $name, &$list)
140 $ret = '';
141 foreach ($list as $plugin_name => $val) {
142 $ret .= '<!-- ' . $plugin_name . ' -->' . "\n";
143 $ret .= '<input type="radio" name="' . $name . '" value="' . $plugin_name . '"'
144 . ' id="radio_plugin_' . $plugin_name . '"'
145 . ' onclick="if(this.checked) { hide_them_all();'
146 .' document.getElementById(\'' . $plugin_name . '_options\').style.display = \'block\'; };'
147 .' return true"'
148 . PMA_pluginIsActive($section, $name, $plugin_name) . '/>' . "\n";
149 $ret .= '<label for="radio_plugin_' . $plugin_name . '">'
150 . PMA_getString($val['text']) . '</label>' . "\n";
151 $ret .= '<br /><br />' . "\n";
153 return $ret;
157 * string PMA_pluginGetOneOption(string $section, string $plugin_name, string $id, array &$opt)
159 * returns single option in a table row
161 * @uses PMA_getString()
162 * @uses PMA_pluginCheckboxCheck()
163 * @uses PMA_pluginGetDefault()
164 * @param string $section name of config section in
165 * $GLOBALS['cfg'][$section] for plugin
166 * @param string $plugin_name unique plugin name
167 * @param string $id option id
168 * @param array &$opt plugin option details
169 * @return string table row with option
171 function PMA_pluginGetOneOption($section, $plugin_name, $id, &$opt)
173 $ret = '';
174 $ret .= '<tr>';
175 if ($opt['type'] == 'bool') {
176 $ret .= '<td colspan="2">';
177 $ret .= '<input type="checkbox" name="' . $plugin_name . '_' . $opt['name'] . '"'
178 . ' value="something" id="checkbox_' . $plugin_name . '_' . $opt['name'] . '"'
179 . ' ' . PMA_pluginCheckboxCheck($section, $plugin_name . '_' . $opt['name']) .' />';
180 $ret .= '<label for="checkbox_' . $plugin_name . '_' . $opt['name'] . '">'
181 . PMA_getString($opt['text']) . '</label>';
182 } elseif ($opt['type'] == 'text') {
183 $ret .= '<td>';
184 $ret .= '<label for="text_' . $plugin_name . '_' . $opt['name'] . '">'
185 . PMA_getString($opt['text']) . '</label>';
186 $ret .= '</td><td>';
187 $ret .= '<input type="text" name="' . $plugin_name . '_' . $opt['name'] . '"'
188 . ' value="' . PMA_pluginGetDefault($section, $plugin_name . '_' . $opt['name']) . '"'
189 . ' id="text_' . $plugin_name . '_' . $opt['name'] . '"'
190 . (isset($opt['size']) ? ' size="' . $opt['size'] . '"' : '' )
191 . (isset($opt['len']) ? ' maxlength="' . $opt['len'] . '"' : '' ) . ' />';
192 } elseif ($opt['type'] == 'select') {
193 $ret .= '<td>';
194 $ret .= '<label for="select_' . $plugin_name . '_' . $opt['name'] . '">'
195 . PMA_getString($opt['text']) . '</label>';
196 $ret .= '</td><td>';
197 $ret .= '<select name="' . $plugin_name . '_' . $opt['name'] . '"'
198 . ' id="select_' . $plugin_name . '_' . $opt['name'] . '">';
199 $default = PMA_pluginGetDefault($section, $plugin_name . '_' . $opt['name']);
200 foreach($opt['values'] as $key => $val) {
201 $ret .= '<option name="' . $key . '"';
202 if ($key == $default) {
203 $ret .= ' selected="selected"';
205 $ret .= '>' . PMA_getString($val) . '</option>';
207 $ret .= '</select>';
208 } elseif ($opt['type'] == 'hidden') {
209 $ret .= '<input type="hidden" name="' . $plugin_name . '_' . $opt['name'] . '"'
210 . ' value="' . PMA_pluginGetDefault($section, $plugin_name . '_' . $opt['name']) . '"' . ' />';
211 } else {
212 /* This should be seen only by plugin writers, so I do not thing this
213 * needs translation. */
214 $ret .= '<td colspan="2">';
215 $ret .= 'UNKNOWN OPTION IN IMPORT PLUGIN ' . $plugin_name . '!';
217 if (isset($opt['doc'])) {
218 $ret .= PMA_showMySQLDocu($opt['doc'][0], $opt['doc'][1]);
220 $ret .= '</td>';
221 $ret .= '</tr>';
222 return $ret;
226 * string PMA_pluginGetOptions(string $section, array &$list)
228 * return html fieldset with editable options for plugin
230 * @uses PMA_getString()
231 * @uses PMA_pluginGetOneOption()
232 * @param string $section name of config section in $GLOBALS['cfg'][$section]
233 * @param array &$list array with plugin configuration defined in plugin file
234 * @return string html fieldset with plugin options
236 function PMA_pluginGetOptions($section, &$list)
238 $ret = '';
239 // Options for plugins that support them
240 foreach ($list as $plugin_name => $val) {
241 $ret .= '<fieldset id="' . $plugin_name . '_options" class="options">';
242 $ret .= '<legend>' . PMA_getString($val['options_text']) . '</legend>';
243 if (isset($val['options'])) {
244 $ret .= '<table class="form">';
245 $ret .= '<tbody>';
246 foreach ($val['options'] as $id => $opt) {
247 $ret .= PMA_pluginGetOneOption($section, $plugin_name, $id, $opt);
249 $ret .= '</tbody>';
250 $ret .= '</table>';
251 } else {
252 $ret .= $GLOBALS['strNoOptions'];
254 $ret .= '</fieldset>';
256 return $ret;
259 function PMA_pluginGetJavascript(&$list) {
260 $ret = '
261 <script type="text/javascript" language="javascript">
262 //<![CDATA[
263 function hide_them_all() {
265 foreach ($list as $plugin_name => $val) {
266 $ret .= 'document.getElementById("' . $plugin_name . '_options").style.display = "none";' . "\n";
268 $ret .= '
271 function init_options() {
272 hide_them_all();
274 foreach ($list as $plugin_name => $val) {
275 $ret .= 'if (document.getElementById("radio_plugin_' . $plugin_name . '").checked) {' . "\n";
276 $ret .= 'document.getElementById("' . $plugin_name . '_options").style.display = "block";' . "\n";
277 $ret .= ' } else ' . "\n";
279 $ret .= '
285 function match_file(fname) {
286 farr = fname.toLowerCase().split(".");
287 if (farr.length != 0) {
288 len = farr.length
289 if (farr[len - 1] == "gz" || farr[len - 1] == "bz2" || farr[len -1] == "zip") len--;
290 switch (farr[len - 1]) {
292 foreach ($list as $plugin_name => $val) {
293 $ret .= 'case "' . $val['extension'] . '" :';
294 $ret .= 'document.getElementById("radio_plugin_' . $plugin_name . '").checked = true;';
295 $ret .= 'init_options();';
296 $ret .= 'break;' . "\n";
298 $ret .='
302 //]]>
303 </script>
305 return $ret;