PageRenderTime 25ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/res/plugins/plugin.php

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