wrap.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. /**
  3. * Include plugin (wrapper component)
  4. *
  5. * @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
  6. * @author Michael Klier <chi@chimeric.de>
  7. * @author Michael Hamann <michael@content-space.de>
  8. */
  9. class syntax_plugin_include_wrap extends DokuWiki_Syntax_Plugin {
  10. function getType() {
  11. return 'formatting';
  12. }
  13. function getSort() {
  14. return 50;
  15. }
  16. function handle($match, $state, $pos, Doku_Handler $handler) {
  17. // this is a syntax plugin that doesn't offer any syntax, so there's nothing to handle by the parser
  18. }
  19. /**
  20. * Wraps the included page in a div and writes section edits for the action component
  21. * so it can detect where an included page starts/ends.
  22. *
  23. * @author Michael Klier <chi@chimeric.de>
  24. * @author Michael Hamann <michael@content-space.de>
  25. */
  26. function render($mode, Doku_Renderer $renderer, $data) {
  27. if ($mode == 'xhtml') {
  28. $state = array_shift($data);
  29. switch($state) {
  30. case 'open':
  31. list($page, $redirect, $secid) = $data;
  32. if ($redirect) {
  33. if (defined('SEC_EDIT_PATTERN')) { // for DokuWiki Greebo and more recent versions
  34. $renderer->startSectionEdit(0, array('target' => 'plugin_include_start', 'name' => $page, 'hid' => ''));
  35. } else {
  36. $renderer->startSectionEdit(0, 'plugin_include_start', $page);
  37. }
  38. } else {
  39. if (defined('SEC_EDIT_PATTERN')) { // for DokuWiki Greebo and more recent versions
  40. $renderer->startSectionEdit(0, array('target' => 'plugin_include_start_noredirect', 'name' => $page, 'hid' => ''));
  41. } else {
  42. $renderer->startSectionEdit(0, 'plugin_include_start_noredirect', $page);
  43. }
  44. }
  45. $renderer->finishSectionEdit();
  46. // Start a new section with type != section so headers in the included page
  47. // won't print section edit buttons of the parent page
  48. if (defined('SEC_EDIT_PATTERN')) { // for DokuWiki Greebo and more recent versions
  49. $renderer->startSectionEdit(0, array('target' => 'plugin_include_end', 'name' => $page, 'hid' => ''));
  50. } else {
  51. $renderer->startSectionEdit(0, 'plugin_include_end', $page);
  52. }
  53. if ($secid === NULL) {
  54. $id = '';
  55. } else {
  56. $id = ' id="'.$secid.'"';
  57. }
  58. $renderer->doc .= '<div class="plugin_include_content plugin_include__' . $page .'"'.$id.'>' . DOKU_LF;
  59. if (is_a($renderer,'renderer_plugin_dw2pdf')) {
  60. $renderer->doc .= '<a name="'.$secid.'" />';
  61. }
  62. break;
  63. case 'close':
  64. $renderer->finishSectionEdit();
  65. $renderer->doc .= '</div>' . DOKU_LF;
  66. break;
  67. }
  68. return true;
  69. }
  70. return false;
  71. }
  72. }
  73. // vim:ts=4:sw=4:et: