Verzeichnisstruktur phpBB-3.3.15


Veröffentlicht
28.08.2024

So funktioniert es


Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück

Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

(Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

Configurator.php

Zuletzt modifiziert: 02.04.2025, 15:04 - Dateigröße: 3.98 KiB


001  <?php
002   
003  /**
004  * @package   s9e\TextFormatter
005  * @copyright Copyright (c) 2010-2022 The s9e authors
006  * @license   http://www.opensource.org/licenses/mit-license.php The MIT License
007  */
008  namespace s9e\TextFormatter\Plugins\Keywords;
009   
010  use s9e\TextFormatter\Configurator\Collections\NormalizedList;
011  use s9e\TextFormatter\Configurator\Helpers\RegexpBuilder;
012  use s9e\TextFormatter\Configurator\Items\Regexp;
013  use s9e\TextFormatter\Configurator\Traits\CollectionProxy;
014  use s9e\TextFormatter\Plugins\ConfiguratorBase;
015   
016  /**
017  * @method mixed   add(string $key, mixed $value) Add an item to this collection
018  * @method array   asConfig()
019  * @method void    clear()                        Empty this collection
020  * @method bool    contains(mixed $value)         Test whether a given value is present in this collection
021  * @method integer count()
022  * @method mixed   current()
023  * @method void    delete(string $key)            Delete an item from this collection
024  * @method bool    exists(string $key)            Test whether an item of given key exists
025  * @method mixed   get(string $key)               Return a value from this collection
026  * @method mixed   indexOf(mixed $value)          Find the index of a given value
027  * @method integer|string key()
028  * @method mixed   next()
029  * @method string  normalizeKey(string $key)      Normalize an item's key
030  * @method mixed   normalizeValue(mixed $value)   Normalize a value for storage
031  * @method bool    offsetExists(string|integer $offset)
032  * @method mixed   offsetGet(string|integer $offset)
033  * @method void    offsetSet(string|integer $offset, mixed $value)
034  * @method void    offsetUnset(string|integer $offset)
035  * @method string  onDuplicate(string|null $action) Query and set the action to take when add() is called with a key that already exists
036  * @method void    rewind()
037  * @method mixed   set(string $key, mixed $value) Set and overwrite a value in this collection
038  * @method bool    valid()
039  */
040  class Configurator extends ConfiguratorBase
041  {
042      use CollectionProxy;
043   
044      /**
045      * @var string Name of the attribute used by this plugin
046      */
047      protected $attrName = 'value';
048   
049      /**
050      * @var bool Whether keywords are case-sensitive
051      */
052      public $caseSensitive = true;
053   
054      /**
055      * @var \s9e\TextFormatter\Configurator\Collections\NormalizedCollection List of [keyword => value]
056      */
057      protected $collection;
058   
059      /**
060      * @var boolean Whether to capture only the first occurence of each keyword
061      */
062      public $onlyFirst = false;
063   
064      /**
065      * @var string Name of the tag used by this plugin
066      */
067      protected $tagName = 'KEYWORD';
068   
069      /**
070      * {@inheritdoc}
071      */
072      protected function setUp()
073      {
074          $this->collection = new NormalizedList;
075   
076          $this->configurator->tags->add($this->tagName)->attributes->add($this->attrName);
077      }
078   
079      /**
080      * {@inheritdoc}
081      */
082      public function asConfig()
083      {
084          if (!count($this->collection))
085          {
086              return;
087          }
088   
089          $config = [
090              'attrName' => $this->attrName,
091              'tagName'  => $this->tagName
092          ];
093   
094          if (!empty($this->onlyFirst))
095          {
096              $config['onlyFirst'] = $this->onlyFirst;
097          }
098   
099          // Sort keywords in order to keep keywords that start with the same characters together. We
100          // also remove duplicates that would otherwise skew the length computation done below
101          $keywords = array_unique(iterator_to_array($this->collection));
102          sort($keywords);
103   
104          // Group keywords by chunks of ~30KB to remain below PCRE's limit
105          $groups   = [];
106          $groupKey = 0;
107          $groupLen = 0;
108          foreach ($keywords as $keyword)
109          {
110              // NOTE: the value 4 is a guesstimate for the cost of each alternation
111              $keywordLen  = 4 + strlen($keyword);
112              $groupLen   += $keywordLen;
113   
114              if ($groupLen > 30000)
115              {
116                  $groupLen = $keywordLen;
117                  ++$groupKey;
118              }
119   
120              $groups[$groupKey][] = $keyword;
121          }
122   
123          foreach ($groups as $keywords)
124          {
125              $regexp = RegexpBuilder::fromList(
126                  $keywords,
127                  ['caseInsensitive' => !$this->caseSensitive]
128              );
129   
130              $regexp = '/\\b' . $regexp . '\\b/S';
131   
132              if (!$this->caseSensitive)
133              {
134                  $regexp .= 'i';
135              }
136   
137              if (preg_match('/[^[:ascii:]]/', $regexp))
138              {
139                  $regexp .= 'u';
140              }
141   
142              $config['regexps'][] = new Regexp($regexp, true);
143          }
144   
145          return $config;
146      }
147  }