PageRenderTime 23ms CodeModel.GetById 9ms RepoModel.GetById 0ms app.codeStats 0ms

/Quản lý website bán phụ tùng oto PHP/phpMyAdmin1/libraries/plugin_interface.lib.php

https://gitlab.com/phamngsinh/baitaplon_sinhvien
PHP | 370 lines | 235 code | 10 blank | 125 comment | 45 complexity | 67b63d9244f152940d67defe3be70273 MD5 | raw file
  1. <?php
  2. /* $Id: plugin_interface.lib.php 9131 2006-06-25 11:42:18Z lem9 $ */
  3. // vim: expandtab sw=4 ts=4 sts=4:
  4. /**
  5. * Generic plugin interface.
  6. */
  7. /**
  8. * array PMA_getPlugins(string $plugins_dir, mixed $plugin_param)
  9. *
  10. * Reads all plugin information from directory $plugins_dir.
  11. *
  12. * @uses ksort()
  13. * @uses opendir()
  14. * @uses readdir()
  15. * @uses is_file()
  16. * @uses eregi()
  17. * @param string $plugins_dir directrory with plugins
  18. * @param mixed $plugin_param parameter to plugin by which they can decide whether they can work
  19. * @return array list of plugins
  20. */
  21. function PMA_getPlugins($plugins_dir, $plugin_param)
  22. {
  23. /* Scan for plugins */
  24. $plugin_list = array();
  25. if ($handle = @opendir($plugins_dir)) {
  26. $is_first = 0;
  27. while ($file = @readdir($handle)) {
  28. if (is_file($plugins_dir . $file) && eregi('\.php$', $file)) {
  29. include $plugins_dir . $file;
  30. }
  31. }
  32. }
  33. ksort($plugin_list);
  34. return $plugin_list;
  35. }
  36. /**
  37. * string PMA_getString(string $name)
  38. *
  39. * returns locale string for $name or $name if no locale is found
  40. *
  41. * @uses $GLOBALS
  42. * @param string $name for local string
  43. * @return string locale string for $name
  44. */
  45. function PMA_getString($name)
  46. {
  47. return isset($GLOBALS[$name]) ? $GLOBALS[$name] : $name;
  48. }
  49. /**
  50. * string PMA_pluginCheckboxCheck(string $section, string $opt)
  51. *
  52. * returns html input tag option 'checked' if plugin $opt should be set by config or request
  53. *
  54. * @uses $_REQUEST
  55. * @uses $GLOBALS['cfg']
  56. * @uses $GLOBALS['timeout_passed']
  57. * @param string $section name of config section in
  58. * $GLOBALS['cfg'][$section] for plugin
  59. * @param string $opt name of option
  60. * @return string hmtl input tag option 'checked'
  61. */
  62. function PMA_pluginCheckboxCheck($section, $opt)
  63. {
  64. if ((isset($GLOBALS['timeout_passed']) && $GLOBALS['timeout_passed'] && isset($_REQUEST[$opt])) ||
  65. (isset($GLOBALS['cfg'][$section][$opt]) && $GLOBALS['cfg'][$section][$opt])) {
  66. return ' checked="checked"';
  67. }
  68. return '';
  69. }
  70. /**
  71. * string PMA_pluginGetDefault(string $section, string $opt)
  72. *
  73. * returns default value for option $opt
  74. *
  75. * @uses htmlspecialchars()
  76. * @uses $_REQUEST
  77. * @uses $GLOBALS['cfg']
  78. * @uses $GLOBALS['timeout_passed']
  79. * @param string $section name of config section in
  80. * $GLOBALS['cfg'][$section] for plugin
  81. * @param string $opt name of option
  82. * @return string default value for option $opt
  83. */
  84. function PMA_pluginGetDefault($section, $opt)
  85. {
  86. if (isset($GLOBALS['timeout_passed']) && $GLOBALS['timeout_passed'] && isset($_REQUEST[$opt])) {
  87. return htmlspecialchars($_REQUEST[$opt]);
  88. } elseif (isset($GLOBALS['cfg'][$section][$opt])) {
  89. $matches = array();
  90. /* Possibly replace localised texts */
  91. if (preg_match_all('/(str[A-Z][A-Za-z0-9]*)/', $GLOBALS['cfg'][$section][$opt], $matches)) {
  92. $val = $GLOBALS['cfg'][$section][$opt];
  93. foreach($matches[0] as $match) {
  94. if (isset($GLOBALS[$match])) {
  95. $val = str_replace($match, $GLOBALS[$match], $val);
  96. }
  97. }
  98. return htmlspecialchars($val);
  99. } else {
  100. return htmlspecialchars($GLOBALS['cfg'][$section][$opt]);
  101. }
  102. }
  103. return '';
  104. }
  105. /**
  106. * string PMA_pluginIsActive(string $section, string $opt, string $val)
  107. *
  108. * returns html input tag option 'checked' if option $opt should be set by config or request
  109. *
  110. * @uses $_REQUEST
  111. * @uses $GLOBALS['cfg']
  112. * @uses $GLOBALS['timeout_passed']
  113. * @param string $section name of config section in
  114. * $GLOBALS['cfg'][$section] for plugin
  115. * @param string $opt name of option
  116. * @param string $val value of option to check against
  117. * @return string html input tag option 'checked'
  118. */
  119. function PMA_pluginIsActive($section, $opt, $val)
  120. {
  121. if ( ! empty($GLOBALS['timeout_passed']) && isset($_REQUEST[$opt])) {
  122. if ($_REQUEST[$opt] == $val) {
  123. return ' checked="checked"';
  124. }
  125. } elseif (isset($GLOBALS['cfg'][$section][$opt]) && $GLOBALS['cfg'][$section][$opt] == $val) {
  126. return ' checked="checked"';
  127. }
  128. return '';
  129. }
  130. /**
  131. * string PMA_pluginGetChoice(string $section, string $name, array &$list, string $cfgname)
  132. *
  133. * returns html radio form element for plugin choice
  134. *
  135. * @uses PMA_pluginIsActive()
  136. * @uses PMA_getString()
  137. * @param string $section name of config section in
  138. * $GLOBALS['cfg'][$section] for plugin
  139. * @param string $name name of radio element
  140. * @param array &$list array with plugin configuration defined in plugin file
  141. * @param string $cfgname name of config value, if none same as $name
  142. * @return string html input radio tag
  143. */
  144. function PMA_pluginGetChoice($section, $name, &$list, $cfgname = NULL)
  145. {
  146. if (!isset($cfgname)) {
  147. $cfgname = $name;
  148. }
  149. $ret = '';
  150. foreach ($list as $plugin_name => $val) {
  151. $ret .= '<!-- ' . $plugin_name . ' -->' . "\n";
  152. $ret .= '<input type="radio" name="' . $name . '" value="' . $plugin_name . '"'
  153. . ' id="radio_plugin_' . $plugin_name . '"'
  154. . ' onclick="if(this.checked) { hide_them_all();';
  155. if (isset($val['force_file'])) {
  156. $ret .= 'document.getElementById(\'checkbox_dump_asfile\').checked = true;';
  157. }
  158. $ret .= ' document.getElementById(\'' . $plugin_name . '_options\').style.display = \'block\'; };'
  159. .' return true"'
  160. . PMA_pluginIsActive($section, $cfgname, $plugin_name) . '/>' . "\n";
  161. $ret .= '<label for="radio_plugin_' . $plugin_name . '">'
  162. . PMA_getString($val['text']) . '</label>' . "\n";
  163. $ret .= '<br /><br />' . "\n";
  164. }
  165. return $ret;
  166. }
  167. /**
  168. * string PMA_pluginGetOneOption(string $section, string $plugin_name, string $id, array &$opt)
  169. *
  170. * returns single option in a table row
  171. *
  172. * @uses PMA_getString()
  173. * @uses PMA_pluginCheckboxCheck()
  174. * @uses PMA_pluginGetDefault()
  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
  181. */
  182. function PMA_pluginGetOneOption($section, $plugin_name, $id, &$opt)
  183. {
  184. $ret = "\n";
  185. if ($opt['type'] == 'bool') {
  186. $ret .= '<div class="formelementrow">' . "\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 &amp;&amp; '
  193. . '(!document.getElementById(\'checkbox_' . $plugin_name . '_' .$opt['force'] . '\') '
  194. . '|| !document.getElementById(\'checkbox_' . $plugin_name . '_' .$opt['force'] . '\').checked)) '
  195. . 'return false; else return true;"';
  196. }
  197. $ret .= ' />';
  198. $ret .= '<label for="checkbox_' . $plugin_name . '_' . $opt['name'] . '">'
  199. . PMA_getString($opt['text']) . '</label>';
  200. $ret .= '</div>' . "\n";
  201. } elseif ($opt['type'] == 'text') {
  202. $ret .= '<div class="formelementrow">' . "\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. $ret .= '</div>' . "\n";
  211. } elseif ($opt['type'] == 'message_only') {
  212. $ret .= '<div class="formelementrow">' . "\n";
  213. $ret .= '<label for="text_' . $plugin_name . '_' . $opt['name'] . '" class="desc">'
  214. . PMA_getString($opt['text']) . '</label>';
  215. $ret .= '</div>' . "\n";
  216. } elseif ($opt['type'] == 'select') {
  217. $ret .= '<div class="formelementrow">' . "\n";
  218. $ret .= '<label for="select_' . $plugin_name . '_' . $opt['name'] . '" class="desc">'
  219. . PMA_getString($opt['text']) . '</label>';
  220. $ret .= '<select name="' . $plugin_name . '_' . $opt['name'] . '"'
  221. . ' id="select_' . $plugin_name . '_' . $opt['name'] . '">';
  222. $default = PMA_pluginGetDefault($section, $plugin_name . '_' . $opt['name']);
  223. foreach($opt['values'] as $key => $val) {
  224. $ret .= '<option name="' . $key . '"';
  225. if ($key == $default) {
  226. $ret .= ' selected="selected"';
  227. }
  228. $ret .= '>' . PMA_getString($val) . '</option>';
  229. }
  230. $ret .= '</select>';
  231. $ret .= '</div>' . "\n";
  232. } elseif ($opt['type'] == 'hidden') {
  233. $ret .= '<input type="hidden" name="' . $plugin_name . '_' . $opt['name'] . '"'
  234. . ' value="' . PMA_pluginGetDefault($section, $plugin_name . '_' . $opt['name']) . '"' . ' />';
  235. } elseif ($opt['type'] == 'bgroup') {
  236. $ret .= '<fieldset><legend>';
  237. /* No checkbox without name */
  238. if (!empty($opt['name'])) {
  239. $ret .= '<input type="checkbox" name="' . $plugin_name . '_' . $opt['name'] . '"'
  240. . ' value="something" id="checkbox_' . $plugin_name . '_' . $opt['name'] . '"'
  241. . ' ' . PMA_pluginCheckboxCheck($section, $plugin_name . '_' . $opt['name']);
  242. if (isset($opt['force'])) {
  243. /* Same code is also few lines higher, update both if needed */
  244. $ret .= ' onclick="if (!this.checked &amp;&amp; '
  245. . '(!document.getElementById(\'checkbox_' . $plugin_name . '_' .$opt['force'] . '\') '
  246. . '|| !document.getElementById(\'checkbox_' . $plugin_name . '_' .$opt['force'] . '\').checked)) '
  247. . 'return false; else return true;"';
  248. }
  249. $ret .= ' />';
  250. $ret .= '<label for="checkbox_' . $plugin_name . '_' . $opt['name'] . '">'
  251. . PMA_getString($opt['text']) . '</label>';
  252. } else {
  253. $ret .= PMA_getString($opt['text']);
  254. }
  255. $ret .= '</legend>';
  256. } elseif ($opt['type'] == 'egroup') {
  257. $ret .= '</fieldset>';
  258. } else {
  259. /* This should be seen only by plugin writers, so I do not thing this
  260. * needs translation. */
  261. $ret .= 'UNKNOWN OPTION ' . $opt['type'] . ' IN IMPORT PLUGIN ' . $plugin_name . '!';
  262. }
  263. if (isset($opt['doc'])) {
  264. $ret .= PMA_showMySQLDocu($opt['doc'][0], $opt['doc'][1]);
  265. }
  266. $ret .= "\n";
  267. return $ret;
  268. }
  269. /**
  270. * string PMA_pluginGetOptions(string $section, array &$list)
  271. *
  272. * return html fieldset with editable options for plugin
  273. *
  274. * @uses PMA_getString()
  275. * @uses PMA_pluginGetOneOption()
  276. * @param string $section name of config section in $GLOBALS['cfg'][$section]
  277. * @param array &$list array with plugin configuration defined in plugin file
  278. * @return string html fieldset with plugin options
  279. */
  280. function PMA_pluginGetOptions($section, &$list)
  281. {
  282. $ret = '';
  283. // Options for plugins that support them
  284. foreach ($list as $plugin_name => $val) {
  285. $ret .= '<fieldset id="' . $plugin_name . '_options" class="options">';
  286. $ret .= '<legend>' . PMA_getString($val['options_text']) . '</legend>';
  287. $count = 0;
  288. if (isset($val['options']) && count($val['options']) > 0) {
  289. foreach ($val['options'] as $id => $opt) {
  290. if ($opt['type'] != 'hidden') $count++;
  291. $ret .= PMA_pluginGetOneOption($section, $plugin_name, $id, $opt);
  292. }
  293. }
  294. if ($count == 0) {
  295. $ret .= $GLOBALS['strNoOptions'];
  296. }
  297. $ret .= '</fieldset>';
  298. }
  299. return $ret;
  300. }
  301. /**
  302. * string PMA_pluginGetJavascript(array &$list)
  303. *
  304. * return html/javascript code which is needed for handling plugin stuff
  305. *
  306. * @param array &$list array with plugin configuration defined in plugin file
  307. * @return string html fieldset with plugin options
  308. */
  309. function PMA_pluginGetJavascript(&$list) {
  310. $ret = '
  311. <script type="text/javascript" language="javascript">
  312. //<![CDATA[
  313. function hide_them_all() {
  314. ';
  315. foreach ($list as $plugin_name => $val) {
  316. $ret .= 'document.getElementById("' . $plugin_name . '_options").style.display = "none";' . "\n";
  317. }
  318. $ret .= '
  319. }
  320. function init_options() {
  321. hide_them_all();
  322. ';
  323. foreach ($list as $plugin_name => $val) {
  324. $ret .= 'if (document.getElementById("radio_plugin_' . $plugin_name . '").checked) {' . "\n";
  325. if (isset($val['force_file'])) {
  326. $ret .= 'document.getElementById(\'checkbox_dump_asfile\').checked = true;' . "\n";
  327. }
  328. $ret .= 'document.getElementById("' . $plugin_name . '_options").style.display = "block";' . "\n";
  329. $ret .= ' } else ' . "\n";
  330. }
  331. $ret .= '
  332. {
  333. ;
  334. }
  335. }
  336. function match_file(fname) {
  337. farr = fname.toLowerCase().split(".");
  338. if (farr.length != 0) {
  339. len = farr.length
  340. if (farr[len - 1] == "gz" || farr[len - 1] == "bz2" || farr[len -1] == "zip") len--;
  341. switch (farr[len - 1]) {
  342. ';
  343. foreach ($list as $plugin_name => $val) {
  344. $ret .= 'case "' . $val['extension'] . '" :';
  345. $ret .= 'document.getElementById("radio_plugin_' . $plugin_name . '").checked = true;';
  346. $ret .= 'init_options();';
  347. $ret .= 'break;' . "\n";
  348. }
  349. $ret .='
  350. }
  351. }
  352. }
  353. //]]>
  354. </script>
  355. ';
  356. return $ret;
  357. }
  358. ?>