[ Index ]

PHP Cross Reference of DokuWiki

title

Body

[close]

/inc/Parsing/ParserMode/ -> Wordblock.php (source)

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