PageRenderTime 52ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/opt/adminer/plugins/plugin.php

https://github.com/laposa/onxshop
PHP | 365 lines | 285 code | 67 blank | 13 comment | 8 complexity | 8218686ed9e9b696c85780b41f0df279 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. <?php
  2. /** Adminer customization allowing usage of plugins
  3. * @link https://www.adminer.org/plugins/#use
  4. * @author Jakub Vrana, https://www.vrana.cz/
  5. * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
  6. * @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2 (one or other)
  7. */
  8. class AdminerPlugin extends Adminer {
  9. /** @access protected */
  10. var $plugins;
  11. function _findRootClass($class) { // is_subclass_of(string, string) is available since PHP 5.0.3
  12. do {
  13. $return = $class;
  14. } while ($class = get_parent_class($class));
  15. return $return;
  16. }
  17. /** Register plugins
  18. * @param array object instances or null to register all classes starting by 'Adminer'
  19. */
  20. function __construct($plugins) {
  21. if ($plugins === null) {
  22. $plugins = array();
  23. foreach (get_declared_classes() as $class) {
  24. if (preg_match('~^Adminer.~i', $class) && strcasecmp($this->_findRootClass($class), 'Adminer')) { //! can use interface
  25. $plugins[$class] = new $class;
  26. }
  27. }
  28. }
  29. $this->plugins = $plugins;
  30. //! it is possible to use ReflectionObject to find out which plugins defines which methods at once
  31. }
  32. function _callParent($function, $args) {
  33. return call_user_func_array(array('parent', $function), $args);
  34. }
  35. function _applyPlugin($function, $args) {
  36. foreach ($this->plugins as $plugin) {
  37. if (method_exists($plugin, $function)) {
  38. switch (count($args)) { // call_user_func_array() doesn't work well with references
  39. case 0: $return = $plugin->$function(); break;
  40. case 1: $return = $plugin->$function($args[0]); break;
  41. case 2: $return = $plugin->$function($args[0], $args[1]); break;
  42. case 3: $return = $plugin->$function($args[0], $args[1], $args[2]); break;
  43. case 4: $return = $plugin->$function($args[0], $args[1], $args[2], $args[3]); break;
  44. case 5: $return = $plugin->$function($args[0], $args[1], $args[2], $args[3], $args[4]); break;
  45. case 6: $return = $plugin->$function($args[0], $args[1], $args[2], $args[3], $args[4], $args[5]); break;
  46. default: trigger_error('Too many parameters.', E_USER_WARNING);
  47. }
  48. if ($return !== null) {
  49. return $return;
  50. }
  51. }
  52. }
  53. return $this->_callParent($function, $args);
  54. }
  55. function _appendPlugin($function, $args) {
  56. $return = $this->_callParent($function, $args);
  57. foreach ($this->plugins as $plugin) {
  58. if (method_exists($plugin, $function)) {
  59. $return += call_user_func_array(array($plugin, $function), $args);
  60. }
  61. }
  62. return $return;
  63. }
  64. // appendPlugin
  65. function dumpFormat() {
  66. $args = func_get_args();
  67. return $this->_appendPlugin(__FUNCTION__, $args);
  68. }
  69. function dumpOutput() {
  70. $args = func_get_args();
  71. return $this->_appendPlugin(__FUNCTION__, $args);
  72. }
  73. function editFunctions($field) {
  74. $args = func_get_args();
  75. return $this->_appendPlugin(__FUNCTION__, $args);
  76. }
  77. // applyPlugin
  78. function name() {
  79. $args = func_get_args();
  80. return $this->_applyPlugin(__FUNCTION__, $args);
  81. }
  82. function credentials() {
  83. $args = func_get_args();
  84. return $this->_applyPlugin(__FUNCTION__, $args);
  85. }
  86. function permanentLogin($create = false) {
  87. $args = func_get_args();
  88. return $this->_applyPlugin(__FUNCTION__, $args);
  89. }
  90. function database() {
  91. $args = func_get_args();
  92. return $this->_applyPlugin(__FUNCTION__, $args);
  93. }
  94. function schemas() {
  95. $args = func_get_args();
  96. return $this->_applyPlugin(__FUNCTION__, $args);
  97. }
  98. function databases($flush = true) {
  99. $args = func_get_args();
  100. return $this->_applyPlugin(__FUNCTION__, $args);
  101. }
  102. function queryTimeout() {
  103. $args = func_get_args();
  104. return $this->_applyPlugin(__FUNCTION__, $args);
  105. }
  106. function headers() {
  107. $args = func_get_args();
  108. return $this->_applyPlugin(__FUNCTION__, $args);
  109. }
  110. function head() {
  111. $args = func_get_args();
  112. return $this->_applyPlugin(__FUNCTION__, $args);
  113. }
  114. function loginForm() {
  115. $args = func_get_args();
  116. return $this->_applyPlugin(__FUNCTION__, $args);
  117. }
  118. function login($login, $password) {
  119. $args = func_get_args();
  120. return $this->_applyPlugin(__FUNCTION__, $args);
  121. }
  122. function tableName($tableStatus) {
  123. $args = func_get_args();
  124. return $this->_applyPlugin(__FUNCTION__, $args);
  125. }
  126. function fieldName($field, $order = 0) {
  127. $args = func_get_args();
  128. return $this->_applyPlugin(__FUNCTION__, $args);
  129. }
  130. function selectLinks($tableStatus, $set = "") {
  131. $args = func_get_args();
  132. return $this->_applyPlugin(__FUNCTION__, $args);
  133. }
  134. function foreignKeys($table) {
  135. $args = func_get_args();
  136. return $this->_applyPlugin(__FUNCTION__, $args);
  137. }
  138. function backwardKeys($table, $tableName) {
  139. $args = func_get_args();
  140. return $this->_applyPlugin(__FUNCTION__, $args);
  141. }
  142. function backwardKeysPrint($backwardKeys, $row) {
  143. $args = func_get_args();
  144. return $this->_applyPlugin(__FUNCTION__, $args);
  145. }
  146. function selectQuery($query, $time) {
  147. $args = func_get_args();
  148. return $this->_applyPlugin(__FUNCTION__, $args);
  149. }
  150. function sqlCommandQuery($query) {
  151. $args = func_get_args();
  152. return $this->_applyPlugin(__FUNCTION__, $args);
  153. }
  154. function rowDescription($table) {
  155. $args = func_get_args();
  156. return $this->_applyPlugin(__FUNCTION__, $args);
  157. }
  158. function rowDescriptions($rows, $foreignKeys) {
  159. $args = func_get_args();
  160. return $this->_applyPlugin(__FUNCTION__, $args);
  161. }
  162. function selectLink($val, $field) {
  163. $args = func_get_args();
  164. return $this->_applyPlugin(__FUNCTION__, $args);
  165. }
  166. function selectVal($val, $link, $field, $original) {
  167. $args = func_get_args();
  168. return $this->_applyPlugin(__FUNCTION__, $args);
  169. }
  170. function editVal($val, $field) {
  171. $args = func_get_args();
  172. return $this->_applyPlugin(__FUNCTION__, $args);
  173. }
  174. function tableStructurePrint($fields) {
  175. $args = func_get_args();
  176. return $this->_applyPlugin(__FUNCTION__, $args);
  177. }
  178. function tableIndexesPrint($indexes) {
  179. $args = func_get_args();
  180. return $this->_applyPlugin(__FUNCTION__, $args);
  181. }
  182. function selectColumnsPrint($select, $columns) {
  183. $args = func_get_args();
  184. return $this->_applyPlugin(__FUNCTION__, $args);
  185. }
  186. function selectSearchPrint($where, $columns, $indexes) {
  187. $args = func_get_args();
  188. return $this->_applyPlugin(__FUNCTION__, $args);
  189. }
  190. function selectOrderPrint($order, $columns, $indexes) {
  191. $args = func_get_args();
  192. return $this->_applyPlugin(__FUNCTION__, $args);
  193. }
  194. function selectLimitPrint($limit) {
  195. $args = func_get_args();
  196. return $this->_applyPlugin(__FUNCTION__, $args);
  197. }
  198. function selectLengthPrint($text_length) {
  199. $args = func_get_args();
  200. return $this->_applyPlugin(__FUNCTION__, $args);
  201. }
  202. function selectActionPrint($indexes) {
  203. $args = func_get_args();
  204. return $this->_applyPlugin(__FUNCTION__, $args);
  205. }
  206. function selectCommandPrint() {
  207. $args = func_get_args();
  208. return $this->_applyPlugin(__FUNCTION__, $args);
  209. }
  210. function selectImportPrint() {
  211. $args = func_get_args();
  212. return $this->_applyPlugin(__FUNCTION__, $args);
  213. }
  214. function selectEmailPrint($emailFields, $columns) {
  215. $args = func_get_args();
  216. return $this->_applyPlugin(__FUNCTION__, $args);
  217. }
  218. function selectColumnsProcess($columns, $indexes) {
  219. $args = func_get_args();
  220. return $this->_applyPlugin(__FUNCTION__, $args);
  221. }
  222. function selectSearchProcess($fields, $indexes) {
  223. $args = func_get_args();
  224. return $this->_applyPlugin(__FUNCTION__, $args);
  225. }
  226. function selectOrderProcess($fields, $indexes) {
  227. $args = func_get_args();
  228. return $this->_applyPlugin(__FUNCTION__, $args);
  229. }
  230. function selectLimitProcess() {
  231. $args = func_get_args();
  232. return $this->_applyPlugin(__FUNCTION__, $args);
  233. }
  234. function selectLengthProcess() {
  235. $args = func_get_args();
  236. return $this->_applyPlugin(__FUNCTION__, $args);
  237. }
  238. function selectEmailProcess($where, $foreignKeys) {
  239. $args = func_get_args();
  240. return $this->_applyPlugin(__FUNCTION__, $args);
  241. }
  242. function selectQueryBuild($select, $where, $group, $order, $limit, $page) {
  243. $args = func_get_args();
  244. return $this->_applyPlugin(__FUNCTION__, $args);
  245. }
  246. function messageQuery($query, $time) {
  247. $args = func_get_args();
  248. return $this->_applyPlugin(__FUNCTION__, $args);
  249. }
  250. function editInput($table, $field, $attrs, $value) {
  251. $args = func_get_args();
  252. return $this->_applyPlugin(__FUNCTION__, $args);
  253. }
  254. function editHint($table, $field, $value) {
  255. $args = func_get_args();
  256. return $this->_applyPlugin(__FUNCTION__, $args);
  257. }
  258. function processInput($field, $value, $function = "") {
  259. $args = func_get_args();
  260. return $this->_applyPlugin(__FUNCTION__, $args);
  261. }
  262. function dumpDatabase($db) {
  263. $args = func_get_args();
  264. return $this->_applyPlugin(__FUNCTION__, $args);
  265. }
  266. function dumpTable($table, $style, $is_view = 0) {
  267. $args = func_get_args();
  268. return $this->_applyPlugin(__FUNCTION__, $args);
  269. }
  270. function dumpData($table, $style, $query) {
  271. $args = func_get_args();
  272. return $this->_applyPlugin(__FUNCTION__, $args);
  273. }
  274. function dumpFilename($identifier) {
  275. $args = func_get_args();
  276. return $this->_applyPlugin(__FUNCTION__, $args);
  277. }
  278. function dumpHeaders($identifier, $multi_table = false) {
  279. $args = func_get_args();
  280. return $this->_applyPlugin(__FUNCTION__, $args);
  281. }
  282. function homepage() {
  283. $args = func_get_args();
  284. return $this->_applyPlugin(__FUNCTION__, $args);
  285. }
  286. function navigation($missing) {
  287. $args = func_get_args();
  288. return $this->_applyPlugin(__FUNCTION__, $args);
  289. }
  290. function databasesPrint($missing) {
  291. $args = func_get_args();
  292. return $this->_applyPlugin(__FUNCTION__, $args);
  293. }
  294. function tablesPrint($tables) {
  295. $args = func_get_args();
  296. return $this->_applyPlugin(__FUNCTION__, $args);
  297. }
  298. }