Wordblock.php 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. namespace dokuwiki\Parsing\ParserMode;
  3. use dokuwiki\Parsing\Lexer\Lexer;
  4. /**
  5. * @fixme is this actually used?
  6. */
  7. class Wordblock extends AbstractMode
  8. {
  9. protected $badwords = array();
  10. protected $pattern = '';
  11. /**
  12. * Wordblock constructor.
  13. * @param $badwords
  14. */
  15. public function __construct($badwords)
  16. {
  17. $this->badwords = $badwords;
  18. }
  19. /** @inheritdoc */
  20. public function preConnect()
  21. {
  22. if (count($this->badwords) == 0 || $this->pattern != '') {
  23. return;
  24. }
  25. $sep = '';
  26. foreach ($this->badwords as $badword) {
  27. $this->pattern .= $sep.'(?<=\b)(?i)'. Lexer::escape($badword).'(?-i)(?=\b)';
  28. $sep = '|';
  29. }
  30. }
  31. /** @inheritdoc */
  32. public function connectTo($mode)
  33. {
  34. if (strlen($this->pattern) > 0) {
  35. $this->Lexer->addSpecialPattern($this->pattern, $mode, 'wordblock');
  36. }
  37. }
  38. /** @inheritdoc */
  39. public function getSort()
  40. {
  41. return 250;
  42. }
  43. }