Smiley.php 1002 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. namespace dokuwiki\Parsing\ParserMode;
  3. use dokuwiki\Parsing\Lexer\Lexer;
  4. class Smiley extends AbstractMode
  5. {
  6. protected $smileys = array();
  7. protected $pattern = '';
  8. /**
  9. * Smiley constructor.
  10. * @param string[] $smileys
  11. */
  12. public function __construct($smileys)
  13. {
  14. $this->smileys = $smileys;
  15. }
  16. /** @inheritdoc */
  17. public function preConnect()
  18. {
  19. if (!count($this->smileys) || $this->pattern != '') return;
  20. $sep = '';
  21. foreach ($this->smileys as $smiley) {
  22. $this->pattern .= $sep.'(?<=\W|^)'. Lexer::escape($smiley).'(?=\W|$)';
  23. $sep = '|';
  24. }
  25. }
  26. /** @inheritdoc */
  27. public function connectTo($mode)
  28. {
  29. if (!count($this->smileys)) return;
  30. if (strlen($this->pattern) > 0) {
  31. $this->Lexer->addSpecialPattern($this->pattern, $mode, 'smiley');
  32. }
  33. }
  34. /** @inheritdoc */
  35. public function getSort()
  36. {
  37. return 230;
  38. }
  39. }