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.
 
 
 
 
 

147 lines
6.1 KiB

  1. <?php
  2. /**
  3. * Action Component for the Wrap Plugin
  4. *
  5. * @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
  6. * @author Andreas Gohr <andi@splitbrain.org>
  7. */
  8. class action_plugin_wrap extends DokuWiki_Action_Plugin {
  9. /**
  10. * register the eventhandlers
  11. *
  12. * @author Andreas Gohr <andi@splitbrain.org>
  13. */
  14. function register(Doku_Event_Handler $controller){
  15. $controller->register_hook('TOOLBAR_DEFINE', 'AFTER', $this, 'handle_toolbar', array ());
  16. $controller->register_hook('HTML_SECEDIT_BUTTON', 'BEFORE', $this, 'handle_secedit_button');
  17. }
  18. function handle_toolbar(Doku_Event $event, $param) {
  19. $syntaxDiv = $this->getConf('syntaxDiv');
  20. $syntaxSpan = $this->getConf('syntaxSpan');
  21. $event->data[] = array (
  22. 'type' => 'picker',
  23. 'title' => $this->getLang('picker'),
  24. 'icon' => '../../plugins/wrap/images/toolbar/picker.png',
  25. 'list' => array(
  26. array(
  27. 'type' => 'format',
  28. 'title' => $this->getLang('column'),
  29. 'icon' => '../../plugins/wrap/images/toolbar/column.png',
  30. 'open' => '<'.$syntaxDiv.' group>\n<'.$syntaxDiv.' half column>\n',
  31. 'close' => '\n</'.$syntaxDiv.'>\n\n<'.$syntaxDiv.' half column>\n\n</'.$syntaxDiv.'>\n</'.$syntaxDiv.'>\n',
  32. ),
  33. array(
  34. 'type' => 'format',
  35. 'title' => $this->getLang('box'),
  36. 'icon' => '../../plugins/wrap/images/toolbar/box.png',
  37. 'open' => '<'.$syntaxDiv.' center round box 60%>\n',
  38. 'close' => '\n</'.$syntaxDiv.'>\n',
  39. ),
  40. array(
  41. 'type' => 'format',
  42. 'title' => $this->getLang('info'),
  43. 'icon' => '../../plugins/wrap/images/note/16/info.png',
  44. 'open' => '<'.$syntaxDiv.' center round info 60%>\n',
  45. 'close' => '\n</'.$syntaxDiv.'>\n',
  46. ),
  47. array(
  48. 'type' => 'format',
  49. 'title' => $this->getLang('tip'),
  50. 'icon' => '../../plugins/wrap/images/note/16/tip.png',
  51. 'open' => '<'.$syntaxDiv.' center round tip 60%>\n',
  52. 'close' => '\n</'.$syntaxDiv.'>\n',
  53. ),
  54. array(
  55. 'type' => 'format',
  56. 'title' => $this->getLang('important'),
  57. 'icon' => '../../plugins/wrap/images/note/16/important.png',
  58. 'open' => '<'.$syntaxDiv.' center round important 60%>\n',
  59. 'close' => '\n</'.$syntaxDiv.'>\n',
  60. ),
  61. array(
  62. 'type' => 'format',
  63. 'title' => $this->getLang('alert'),
  64. 'icon' => '../../plugins/wrap/images/note/16/alert.png',
  65. 'open' => '<'.$syntaxDiv.' center round alert 60%>\n',
  66. 'close' => '\n</'.$syntaxDiv.'>\n',
  67. ),
  68. array(
  69. 'type' => 'format',
  70. 'title' => $this->getLang('help'),
  71. 'icon' => '../../plugins/wrap/images/note/16/help.png',
  72. 'open' => '<'.$syntaxDiv.' center round help 60%>\n',
  73. 'close' => '\n</'.$syntaxDiv.'>\n',
  74. ),
  75. array(
  76. 'type' => 'format',
  77. 'title' => $this->getLang('download'),
  78. 'icon' => '../../plugins/wrap/images/note/16/download.png',
  79. 'open' => '<'.$syntaxDiv.' center round download 60%>\n',
  80. 'close' => '\n</'.$syntaxDiv.'>\n',
  81. ),
  82. array(
  83. 'type' => 'format',
  84. 'title' => $this->getLang('todo'),
  85. 'icon' => '../../plugins/wrap/images/note/16/todo.png',
  86. 'open' => '<'.$syntaxDiv.' center round todo 60%>\n',
  87. 'close' => '\n</'.$syntaxDiv.'>\n',
  88. ),
  89. array(
  90. 'type' => 'insert',
  91. 'title' => $this->getLang('clear'),
  92. 'icon' => '../../plugins/wrap/images/toolbar/clear.png',
  93. 'insert' => '<'.$syntaxDiv.' clear/>\n',
  94. ),
  95. array(
  96. 'type' => 'format',
  97. 'title' => $this->getLang('em'),
  98. 'icon' => '../../plugins/wrap/images/toolbar/em.png',
  99. 'open' => '<'.$syntaxSpan.' em>',
  100. 'close' => '</'.$syntaxSpan.'>',
  101. ),
  102. array(
  103. 'type' => 'format',
  104. 'title' => $this->getLang('hi'),
  105. 'icon' => '../../plugins/wrap/images/toolbar/hi.png',
  106. 'open' => '<'.$syntaxSpan.' hi>',
  107. 'close' => '</'.$syntaxSpan.'>',
  108. ),
  109. array(
  110. 'type' => 'format',
  111. 'title' => $this->getLang('lo'),
  112. 'icon' => '../../plugins/wrap/images/toolbar/lo.png',
  113. 'open' => '<'.$syntaxSpan.' lo>',
  114. 'close' => '</'.$syntaxSpan.'>',
  115. ),
  116. )
  117. );
  118. }
  119. /**
  120. * Handle section edit buttons, prevents section buttons inside the wrap plugin from being rendered
  121. *
  122. * @param Doku_Event $event The event object
  123. * @param array $param Parameters for the event
  124. */
  125. public function handle_secedit_button(Doku_Event $event, $param) {
  126. // counter of the number of currently opened wraps
  127. static $wraps = 0;
  128. $data = $event->data;
  129. if ($data['target'] == 'plugin_wrap_start') {
  130. ++$wraps;
  131. } elseif ($data['target'] == 'plugin_wrap_end') {
  132. --$wraps;
  133. } elseif ($wraps > 0 && $data['target'] == 'section') {
  134. $event->preventDefault();
  135. $event->stopPropagation();
  136. $event->result = '';
  137. }
  138. }
  139. }