PluginsController.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * Holds the PhpMyAdmin\Controllers\Server\PluginsController
  5. *
  6. * @package PhpMyAdmin\Controllers
  7. */
  8. declare(strict_types=1);
  9. namespace PhpMyAdmin\Controllers\Server;
  10. use PhpMyAdmin\Controllers\AbstractController;
  11. use PhpMyAdmin\DatabaseInterface;
  12. use PhpMyAdmin\Response;
  13. use PhpMyAdmin\Server\Plugins;
  14. use PhpMyAdmin\Template;
  15. /**
  16. * Handles viewing server plugin details
  17. *
  18. * @package PhpMyAdmin\Controllers
  19. */
  20. class PluginsController extends AbstractController
  21. {
  22. /**
  23. * @var Plugins
  24. */
  25. private $plugins;
  26. /**
  27. * @param Response $response Response object
  28. * @param DatabaseInterface $dbi DatabaseInterface object
  29. * @param Template $template Template object
  30. * @param Plugins $plugins Plugins object
  31. */
  32. public function __construct($response, $dbi, Template $template, Plugins $plugins)
  33. {
  34. parent::__construct($response, $dbi, $template);
  35. $this->plugins = $plugins;
  36. }
  37. /**
  38. * Index action
  39. *
  40. * @return string
  41. */
  42. public function index(): string
  43. {
  44. include ROOT_PATH . 'libraries/server_common.inc.php';
  45. $header = $this->response->getHeader();
  46. $scripts = $header->getScripts();
  47. $scripts->addFile('vendor/jquery/jquery.tablesorter.js');
  48. $scripts->addFile('server/plugins.js');
  49. $plugins = [];
  50. $serverPlugins = $this->plugins->getAll();
  51. foreach ($serverPlugins as $plugin) {
  52. $plugins[$plugin->getType()][] = $plugin->toArray();
  53. }
  54. ksort($plugins);
  55. $cleanTypes = [];
  56. foreach (array_keys($plugins) as $type) {
  57. $cleanTypes[$type] = preg_replace(
  58. '/[^a-z]/',
  59. '',
  60. mb_strtolower($type)
  61. );
  62. }
  63. return $this->template->render('server/plugins/index', [
  64. 'plugins' => $plugins,
  65. 'clean_types' => $cleanTypes,
  66. ]);
  67. }
  68. }