PageRenderTime 41ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 0ms

/local/adminer/lib/plugins/plugin.php

https://github.com/thepurpleblob/gumoodle
PHP | 309 lines | 242 code | 55 blank | 12 comment | 9 complexity | 84f97c9f48abe7cd72142719210758f0 MD5 | raw file
Possible License(s): Apache-2.0, GPL-3.0, BSD-3-Clause, LGPL-2.1, AGPL-3.0, MPL-2.0-no-copyleft-exception, LGPL-3.0
  1. <?php
  2. /** Adminer customization allowing usage of plugins
  3. * @author Jakub Vrana, http://www.vrana.cz/
  4. * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
  5. * @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2 (one or other)
  6. */
  7. class AdminerPlugin extends Adminer {
  8. /** @access protected */
  9. var $plugins;
  10. function _findRootClass($class) { // is_subclass_of(string, string) is available since PHP 5.0.3
  11. do {
  12. $return = $class;
  13. } while ($class = get_parent_class($class));
  14. return $return;
  15. }
  16. /** Register plugins
  17. * @param array object instances or null to register all classes starting by 'Adminer'
  18. */
  19. function AdminerPlugin($plugins) {
  20. if (!isset($plugins)) {
  21. $plugins = array();
  22. foreach (get_declared_classes() as $class) {
  23. if (preg_match('~^Adminer.~i', $class) && strcasecmp($this->_findRootClass($class), 'Adminer')) { // can use interface since PHP 5
  24. $plugins[$class] = new $class;
  25. }
  26. }
  27. }
  28. $this->plugins = $plugins;
  29. // it is possible to use ReflectionObject in PHP 5 to find out which plugins defines which methods at once
  30. }
  31. function _callParent($function, $args) {
  32. switch (count($args)) { // call_user_func_array(array('parent', $function), $args) works since PHP 5
  33. case 0: return parent::$function();
  34. case 1: return parent::$function($args[0]);
  35. case 2: return parent::$function($args[0], $args[1]);
  36. case 3: return parent::$function($args[0], $args[1], $args[2]);
  37. case 4: return parent::$function($args[0], $args[1], $args[2], $args[3]);
  38. default: trigger_error('Too many parameters.', E_USER_WARNING);
  39. }
  40. }
  41. function _applyPlugin($function, $args) {
  42. foreach ($this->plugins as $plugin) {
  43. if (method_exists($plugin, $function)) {
  44. switch (count($args)) { // call_user_func_array() doesn't work well with references
  45. case 0: $return = $plugin->$function(); break;
  46. case 1: $return = $plugin->$function($args[0]); break;
  47. case 2: $return = $plugin->$function($args[0], $args[1]); break;
  48. case 3: $return = $plugin->$function($args[0], $args[1], $args[2]); break;
  49. case 4: $return = $plugin->$function($args[0], $args[1], $args[2], $args[3]); break;
  50. default: trigger_error('Too many parameters.', E_USER_WARNING);
  51. }
  52. if (isset($return)) {
  53. return $return;
  54. }
  55. }
  56. }
  57. return $this->_callParent($function, $args);
  58. }
  59. function _appendPlugin($function, $args) {
  60. $return = $this->_callParent($function, $args);
  61. foreach ($this->plugins as $plugin) {
  62. if (method_exists($plugin, $function)) {
  63. $return += call_user_func_array(array($plugin, $function), $args);
  64. }
  65. }
  66. return $return;
  67. }
  68. // appendPlugin
  69. function dumpFormat() {
  70. $args = func_get_args();
  71. return $this->_appendPlugin(__FUNCTION__, $args);
  72. }
  73. function dumpOutput() {
  74. $args = func_get_args();
  75. return $this->_appendPlugin(__FUNCTION__, $args);
  76. }
  77. function editFunctions() {
  78. $args = func_get_args();
  79. return $this->_appendPlugin(__FUNCTION__, $args);
  80. }
  81. // applyPlugin
  82. function name() {
  83. $args = func_get_args();
  84. return $this->_applyPlugin(__FUNCTION__, $args);
  85. }
  86. function credentials() {
  87. $args = func_get_args();
  88. return $this->_applyPlugin(__FUNCTION__, $args);
  89. }
  90. function permanentLogin() {
  91. $args = func_get_args();
  92. return $this->_applyPlugin(__FUNCTION__, $args);
  93. }
  94. function database() {
  95. $args = func_get_args();
  96. return $this->_applyPlugin(__FUNCTION__, $args);
  97. }
  98. function headers() {
  99. $args = func_get_args();
  100. return $this->_applyPlugin(__FUNCTION__, $args);
  101. }
  102. function head() {
  103. $args = func_get_args();
  104. return $this->_applyPlugin(__FUNCTION__, $args);
  105. }
  106. function loginForm() {
  107. $args = func_get_args();
  108. return $this->_applyPlugin(__FUNCTION__, $args);
  109. }
  110. function login() {
  111. $args = func_get_args();
  112. return $this->_applyPlugin(__FUNCTION__, $args);
  113. }
  114. function tableName() {
  115. $args = func_get_args();
  116. return $this->_applyPlugin(__FUNCTION__, $args);
  117. }
  118. function fieldName() {
  119. $args = func_get_args();
  120. return $this->_applyPlugin(__FUNCTION__, $args);
  121. }
  122. function selectLinks() {
  123. $args = func_get_args();
  124. return $this->_applyPlugin(__FUNCTION__, $args);
  125. }
  126. function foreignKeys() {
  127. $args = func_get_args();
  128. return $this->_applyPlugin(__FUNCTION__, $args);
  129. }
  130. function backwardKeys() {
  131. $args = func_get_args();
  132. return $this->_applyPlugin(__FUNCTION__, $args);
  133. }
  134. function backwardKeysPrint() {
  135. $args = func_get_args();
  136. return $this->_applyPlugin(__FUNCTION__, $args);
  137. }
  138. function selectQuery() {
  139. $args = func_get_args();
  140. return $this->_applyPlugin(__FUNCTION__, $args);
  141. }
  142. function rowDescription() {
  143. $args = func_get_args();
  144. return $this->_applyPlugin(__FUNCTION__, $args);
  145. }
  146. function rowDescriptions() {
  147. $args = func_get_args();
  148. return $this->_applyPlugin(__FUNCTION__, $args);
  149. }
  150. function selectVal() {
  151. $args = func_get_args();
  152. return $this->_applyPlugin(__FUNCTION__, $args);
  153. }
  154. function editVal() {
  155. $args = func_get_args();
  156. return $this->_applyPlugin(__FUNCTION__, $args);
  157. }
  158. function selectColumnsPrint() {
  159. $args = func_get_args();
  160. return $this->_applyPlugin(__FUNCTION__, $args);
  161. }
  162. function selectSearchPrint() {
  163. $args = func_get_args();
  164. return $this->_applyPlugin(__FUNCTION__, $args);
  165. }
  166. function selectOrderPrint() {
  167. $args = func_get_args();
  168. return $this->_applyPlugin(__FUNCTION__, $args);
  169. }
  170. function selectLimitPrint() {
  171. $args = func_get_args();
  172. return $this->_applyPlugin(__FUNCTION__, $args);
  173. }
  174. function selectLengthPrint() {
  175. $args = func_get_args();
  176. return $this->_applyPlugin(__FUNCTION__, $args);
  177. }
  178. function selectActionPrint() {
  179. $args = func_get_args();
  180. return $this->_applyPlugin(__FUNCTION__, $args);
  181. }
  182. function selectCommandPrint() {
  183. $args = func_get_args();
  184. return $this->_applyPlugin(__FUNCTION__, $args);
  185. }
  186. function selectImportPrint() {
  187. $args = func_get_args();
  188. return $this->_applyPlugin(__FUNCTION__, $args);
  189. }
  190. function selectEmailPrint() {
  191. $args = func_get_args();
  192. return $this->_applyPlugin(__FUNCTION__, $args);
  193. }
  194. function selectColumnsProcess() {
  195. $args = func_get_args();
  196. return $this->_applyPlugin(__FUNCTION__, $args);
  197. }
  198. function selectSearchProcess() {
  199. $args = func_get_args();
  200. return $this->_applyPlugin(__FUNCTION__, $args);
  201. }
  202. function selectOrderProcess() {
  203. $args = func_get_args();
  204. return $this->_applyPlugin(__FUNCTION__, $args);
  205. }
  206. function selectLimitProcess() {
  207. $args = func_get_args();
  208. return $this->_applyPlugin(__FUNCTION__, $args);
  209. }
  210. function selectLengthProcess() {
  211. $args = func_get_args();
  212. return $this->_applyPlugin(__FUNCTION__, $args);
  213. }
  214. function selectEmailProcess() {
  215. $args = func_get_args();
  216. return $this->_applyPlugin(__FUNCTION__, $args);
  217. }
  218. function messageQuery() {
  219. $args = func_get_args();
  220. return $this->_applyPlugin(__FUNCTION__, $args);
  221. }
  222. function editInput() {
  223. $args = func_get_args();
  224. return $this->_applyPlugin(__FUNCTION__, $args);
  225. }
  226. function processInput() {
  227. $args = func_get_args();
  228. return $this->_applyPlugin(__FUNCTION__, $args);
  229. }
  230. function dumpTable() {
  231. $args = func_get_args();
  232. return $this->_applyPlugin(__FUNCTION__, $args);
  233. }
  234. function dumpData() {
  235. $args = func_get_args();
  236. return $this->_applyPlugin(__FUNCTION__, $args);
  237. }
  238. function dumpHeaders() {
  239. $args = func_get_args();
  240. return $this->_applyPlugin(__FUNCTION__, $args);
  241. }
  242. function homepage() {
  243. $args = func_get_args();
  244. return $this->_applyPlugin(__FUNCTION__, $args);
  245. }
  246. function navigation() {
  247. $args = func_get_args();
  248. return $this->_applyPlugin(__FUNCTION__, $args);
  249. }
  250. function tablesPrint() {
  251. $args = func_get_args();
  252. return $this->_applyPlugin(__FUNCTION__, $args);
  253. }
  254. }