action.php 2.6 KB

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