PluginsController.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. declare(strict_types=1);
  3. namespace PhpMyAdmin\Controllers\Server;
  4. use PhpMyAdmin\Controllers\AbstractController;
  5. use PhpMyAdmin\DatabaseInterface;
  6. use PhpMyAdmin\Response;
  7. use PhpMyAdmin\Server\Plugins;
  8. use PhpMyAdmin\Template;
  9. use PhpMyAdmin\Url;
  10. use function array_keys;
  11. use function ksort;
  12. use function mb_strtolower;
  13. use function preg_replace;
  14. /**
  15. * Handles viewing server plugin details
  16. */
  17. class PluginsController extends AbstractController
  18. {
  19. /** @var Plugins */
  20. private $plugins;
  21. /** @var DatabaseInterface */
  22. private $dbi;
  23. /**
  24. * @param Response $response
  25. * @param DatabaseInterface $dbi
  26. */
  27. public function __construct($response, Template $template, Plugins $plugins, $dbi)
  28. {
  29. parent::__construct($response, $template);
  30. $this->plugins = $plugins;
  31. $this->dbi = $dbi;
  32. }
  33. public function index(): void
  34. {
  35. global $err_url;
  36. $err_url = Url::getFromRoute('/');
  37. if ($this->dbi->isSuperUser()) {
  38. $this->dbi->selectDb('mysql');
  39. }
  40. $this->addScriptFiles(['vendor/jquery/jquery.tablesorter.js', 'server/plugins.js']);
  41. $plugins = [];
  42. $serverPlugins = $this->plugins->getAll();
  43. foreach ($serverPlugins as $plugin) {
  44. $plugins[$plugin->getType()][] = $plugin->toArray();
  45. }
  46. ksort($plugins);
  47. $cleanTypes = [];
  48. foreach (array_keys($plugins) as $type) {
  49. $cleanTypes[$type] = preg_replace(
  50. '/[^a-z]/',
  51. '',
  52. mb_strtolower($type)
  53. );
  54. }
  55. $this->render('server/plugins/index', [
  56. 'plugins' => $plugins,
  57. 'clean_types' => $cleanTypes,
  58. ]);
  59. }
  60. }