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

MapFilter.php

Zuletzt modifiziert: 02.04.2025, 15:04 - Dateigröße: 2.91 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\Configurator\Items\AttributeFilters;
009   
010  use InvalidArgumentException;
011  use s9e\TextFormatter\Configurator\Helpers\RegexpBuilder;
012  use s9e\TextFormatter\Configurator\Items\Regexp;
013   
014  class MapFilter extends AbstractMapFilter
015  {
016      /**
017      * Constructor
018      *
019      * @param  array $map           Associative array in the form [word => replacement]
020      * @param  bool  $caseSensitive Whether this map is case-sensitive
021      * @param  bool  $strict        Whether this map is strict (values with no match are invalid)
022      */
023      public function __construct(array $map = null, $caseSensitive = false, $strict = false)
024      {
025          parent::__construct('s9e\\TextFormatter\\Parser\\AttributeFilters\\MapFilter::filter');
026   
027          $this->resetParameters();
028          $this->addParameterByName('attrValue');
029          $this->addParameterByName('map');
030          $this->setJS('MapFilter.filter');
031   
032          if (isset($map))
033          {
034              $this->setMap($map, $caseSensitive, $strict);
035          }
036      }
037   
038      /**
039      * Set the content of this map
040      *
041      * @param  array $map           Associative array in the form [word => replacement]
042      * @param  bool  $caseSensitive Whether this map is case-sensitive
043      * @param  bool  $strict        Whether this map is strict (values with no match are invalid)
044      * @return void
045      */
046      public function setMap(array $map, $caseSensitive = false, $strict = false)
047      {
048          if (!is_bool($caseSensitive))
049          {
050              throw new InvalidArgumentException('Argument 2 passed to ' . __METHOD__ . ' must be a boolean');
051          }
052   
053          if (!is_bool($strict))
054          {
055              throw new InvalidArgumentException('Argument 3 passed to ' . __METHOD__ . ' must be a boolean');
056          }
057   
058          // Reset the template safeness marks for the new map
059          $this->resetSafeness();
060   
061          // If the map is strict, we can assess its safeness
062          if ($strict)
063          {
064              $this->assessSafeness($map);
065          }
066   
067          // Group values by keys
068          $valueKeys = [];
069          foreach ($map as $key => $value)
070          {
071              $valueKeys[$value][] = $key;
072          }
073   
074          // Now create a regexp and an entry in the map for each group
075          $map = [];
076          foreach ($valueKeys as $value => $keys)
077          {
078              $regexp = RegexpBuilder::fromList(
079                  $keys,
080                  [
081                      'delimiter'       => '/',
082                      'caseInsensitive' => !$caseSensitive
083                  ]
084              );
085              $regexp = '/^' . $regexp . '$/D';
086   
087              // Add the case-insensitive flag if applicable
088              if (!$caseSensitive)
089              {
090                  $regexp .= 'i';
091              }
092   
093              // Add the Unicode flag if the regexp isn't purely ASCII
094              if (!preg_match('#^[[:ascii:]]*$#D', $regexp))
095              {
096                  $regexp .= 'u';
097              }
098   
099              // Add the [regexp,value] pair to the map
100              $map[] = [new Regexp($regexp), $value];
101          }
102   
103          // If the "strict" option is enabled, a catch-all regexp which replaces the value with FALSE
104          // is appended to the list
105          if ($strict)
106          {
107              $map[] = [new Regexp('//'), false];
108          }
109   
110          // Record the map in this filter's variables
111          $this->vars['map'] = $map;
112      }
113  }