You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

91 lines
2.7 KiB

  1. <?php
  2. use dokuwiki\Extension\ActionPlugin;
  3. use dokuwiki\Extension\EventHandler;
  4. use dokuwiki\Extension\Event;
  5. /** DokuWiki Plugin extension (Action Component)
  6. *
  7. * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
  8. * @author Andreas Gohr <andi@splitbrain.org>
  9. */
  10. class action_plugin_extension extends ActionPlugin
  11. {
  12. /**
  13. * Registers a callback function for a given event
  14. *
  15. * @param EventHandler $controller DokuWiki's event controller object
  16. * @return void
  17. */
  18. public function register(EventHandler $controller)
  19. {
  20. $controller->register_hook('AJAX_CALL_UNKNOWN', 'BEFORE', $this, 'info');
  21. }
  22. /**
  23. * Create the detail info for a single plugin
  24. *
  25. * @param Event $event
  26. * @param $param
  27. */
  28. public function info(Event $event, $param)
  29. {
  30. global $USERINFO;
  31. global $INPUT;
  32. if ($event->data != 'plugin_extension') return;
  33. $event->preventDefault();
  34. $event->stopPropagation();
  35. /** @var admin_plugin_extension $admin */
  36. $admin = plugin_load('admin', 'extension');
  37. if (!$admin->isAccessibleByCurrentUser()) {
  38. http_status(403);
  39. echo 'Forbidden';
  40. exit;
  41. }
  42. $ext = $INPUT->str('ext');
  43. if (!$ext) {
  44. http_status(400);
  45. echo 'no extension given';
  46. return;
  47. }
  48. /** @var helper_plugin_extension_extension $extension */
  49. $extension = plugin_load('helper', 'extension_extension');
  50. $extension->setExtension($ext);
  51. $act = $INPUT->str('act');
  52. switch ($act) {
  53. case 'enable':
  54. case 'disable':
  55. if (getSecurityToken() != $INPUT->str('sectok')) {
  56. http_status(403);
  57. echo 'Security Token did not match. Possible CSRF attack.';
  58. return;
  59. }
  60. $extension->$act(); //enables/disables
  61. $reverse = ($act == 'disable') ? 'enable' : 'disable';
  62. $return = [
  63. 'state' => $act . 'd', // isn't English wonderful? :-)
  64. 'reverse' => $reverse,
  65. 'label' => $extension->getLang('btn_' . $reverse),
  66. ];
  67. header('Content-Type: application/json');
  68. echo json_encode($return, JSON_THROW_ON_ERROR);
  69. break;
  70. case 'info':
  71. default:
  72. /** @var helper_plugin_extension_list $list */
  73. $list = plugin_load('helper', 'extension_list');
  74. header('Content-Type: text/html; charset=utf-8');
  75. echo $list->makeInfo($extension);
  76. }
  77. }
  78. }