common.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
  3. if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
  4. require_once(DOKU_PLUGIN.'syntax.php');
  5. class BBCodeExt_simpletag_plugin_base extends DokuWiki_Syntax_Plugin {
  6. public $T= ''; // tag name, used for the wrapper in render stage
  7. public $textwrap= array('', ''); // symbols used to wrap in text mode
  8. function getType() { return 'formatting'; }
  9. function getPType() { return 'normal'; }
  10. function getAllowedTypes() { return array('formatting', 'substition', 'disabled'); }
  11. function getSort() { return 140; }
  12. function makepatterns($bbtag) {
  13. return [ <<<EOT
  14. \[${bbtag}\](?=.*?\x5B/${bbtag}\x5D)
  15. EOT
  16. , "\[/${bbtag}\]" ] ;
  17. }
  18. function setHTMLtag ($t= null) {
  19. $this->T= $t;
  20. }
  21. function settextwraps ($open, $close) {
  22. $this->textwrap= [ $open, $close ];
  23. }
  24. function handle($match, $state, $pos, Doku_Handler $handler) {
  25. switch ($state) {
  26. case DOKU_LEXER_ENTER :
  27. return array($state, [$this->T, $match]);
  28. case DOKU_LEXER_UNMATCHED :
  29. return array($state, [$this->T, $match]);
  30. case DOKU_LEXER_EXIT :
  31. return array($state, [$this->T, $match]);
  32. case DOKU_LEXER_SPECIAL :
  33. return array($state, [$this->T, $match]);
  34. }
  35. return array();
  36. }
  37. function render($mode, Doku_Renderer $renderer, $data) {
  38. list ($state, $match) = $data;
  39. list ($tag, $text) = $match;
  40. if (in_array($mode, ['xhtml', 's5'], true) ) {
  41. switch ($state) {
  42. case DOKU_LEXER_ENTER : {
  43. $renderer->doc.= "<$tag>";
  44. break;
  45. }
  46. case DOKU_LEXER_UNMATCHED : {
  47. $text= $renderer->_xmlEntities($text); // htmlspecialchars($match);
  48. $renderer->doc .= $text;
  49. break;
  50. }
  51. case DOKU_LEXER_EXIT: {
  52. $renderer->doc.= "</${tag}>";
  53. break;
  54. }
  55. } // end switch
  56. return true;
  57. } else if (in_array($mode, ['text'], true) ) {
  58. switch ($state) {
  59. case DOKU_LEXER_ENTER: {
  60. $renderer->doc.= $this->textwrap[0];
  61. break;
  62. }
  63. case DOKU_LEXER_UNMATCHED: {
  64. $text= $renderer->_xmlEntities($text);
  65. $renderer->doc .= $text;
  66. break;
  67. }
  68. case DOKU_LEXER_EXIT : {
  69. $renderer->doc.= $this->textwrap[1];
  70. break;
  71. }
  72. }
  73. return true;
  74. }
  75. return false;
  76. }
  77. }
  78. ?>