Verzeichnisstruktur phpBB-3.2.0


Veröffentlicht
06.01.2017

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

Parser.php

Zuletzt modifiziert: 09.10.2024, 12:58 - Dateigröße: 4.38 KiB


001  <?php
002   
003  /*
004  * @package   s9e\TextFormatter
005  * @copyright Copyright (c) 2010-2016 The s9e Authors
006  * @license   http://www.opensource.org/licenses/mit-license.php The MIT License
007  */
008  namespace s9e\TextFormatter\Plugins\FancyPants;
009  use s9e\TextFormatter\Plugins\ParserBase;
010  class Parser extends ParserBase
011  {
012      protected $hasDoubleQuote;
013      protected $hasSingleQuote;
014      protected $text;
015      public function parse($text, array $matches)
016      {
017          $this->text           = $text;
018          $this->hasSingleQuote = (\strpos($text, "'") !== \false);
019          $this->hasDoubleQuote = (\strpos($text, '"') !== \false);
020          $this->parseSingleQuotes();
021          $this->parseSymbolsAfterDigits();
022          $this->parseSingleQuotePairs();
023          $this->parseDoubleQuotePairs();
024          $this->parseDashesAndEllipses();
025          $this->parseSymbolsInParentheses();
026          $this->parseNotEqualSign();
027          $this->parseGuillemets();
028          unset($this->text);
029      }
030      protected function addTag($tagPos, $tagLen, $chr, $prio = 0)
031      {
032          $tag = $this->parser->addSelfClosingTag($this->config['tagName'], $tagPos, $tagLen, $prio);
033          $tag->setAttribute($this->config['attrName'], $chr);
034          return $tag;
035      }
036      protected function parseDashesAndEllipses()
037      {
038          if (\strpos($this->text, '...') === \false && \strpos($this->text, '--') === \false)
039              return;
040          $chrs = array(
041              '--'  => "\xE2\x80\x93",
042              '---' => "\xE2\x80\x94",
043              '...' => "\xE2\x80\xA6"
044          );
045          $regexp = '/---?|\\.\\.\\./S';
046          \preg_match_all($regexp, $this->text, $matches, \PREG_OFFSET_CAPTURE);
047          foreach ($matches[0] as $m)
048              $this->addTag($m[1], \strlen($m[0]), $chrs[$m[0]]);
049      }
050      protected function parseDoubleQuotePairs()
051      {
052          if ($this->hasDoubleQuote)
053              $this->parseQuotePairs(
054                  '/(?<![0-9\\pL])"[^"\\n]+"(?![0-9\\pL])/uS',
055                  "\xE2\x80\x9C",
056                  "\xE2\x80\x9D"
057              );
058      }
059      protected function parseGuillemets()
060      {
061          if (\strpos($this->text, '<<') === \false)
062              return;
063          $regexp = '/<<( ?)(?! )[^\\n<>]*?[^\\n <>]\\1>>(?!>)/';
064          \preg_match_all($regexp, $this->text, $matches, \PREG_OFFSET_CAPTURE);
065          foreach ($matches[0] as $m)
066          {
067              $left  = $this->addTag($m[1],                     2, "\xC2\xAB");
068              $right = $this->addTag($m[1] + \strlen($m[0]) - 2, 2, "\xC2\xBB");
069              $left->cascadeInvalidationTo($right);
070          }
071      }
072      protected function parseNotEqualSign()
073      {
074          if (\strpos($this->text, '!=') === \false)
075              return;
076          $regexp = '/\\b !=(?= \\b)/';
077          \preg_match_all($regexp, $this->text, $matches, \PREG_OFFSET_CAPTURE);
078          foreach ($matches[0] as $m)
079              $this->addTag($m[1] + 1, 2, "\xE2\x89\xA0");
080      }
081      protected function parseQuotePairs($regexp, $leftQuote, $rightQuote)
082      {
083          \preg_match_all($regexp, $this->text, $matches, \PREG_OFFSET_CAPTURE);
084          foreach ($matches[0] as $m)
085          {
086              $left  = $this->addTag($m[1], 1, $leftQuote);
087              $right = $this->addTag($m[1] + \strlen($m[0]) - 1, 1, $rightQuote);
088              $left->cascadeInvalidationTo($right);
089          }
090      }
091      protected function parseSingleQuotePairs()
092      {
093          if ($this->hasSingleQuote)
094              $this->parseQuotePairs(
095                  "/(?<![0-9\\pL])'[^'\\n]+'(?![0-9\\pL])/uS",
096                  "\xE2\x80\x98",
097                  "\xE2\x80\x99"
098              );
099      }
100      protected function parseSingleQuotes()
101      {
102          if (!$this->hasSingleQuote)
103              return;
104          $regexp = "/(?<=\\pL)'|(?<!\\S)'(?=\\pL|[0-9]{2})/uS";
105          \preg_match_all($regexp, $this->text, $matches, \PREG_OFFSET_CAPTURE);
106          foreach ($matches[0] as $m)
107              $this->addTag($m[1], 1, "\xE2\x80\x99", 10);
108      }
109      protected function parseSymbolsAfterDigits()
110      {
111          if (!$this->hasSingleQuote && !$this->hasDoubleQuote && \strpos($this->text, 'x') === \false)
112              return;
113          $map = array(
114              "'s" => "\xE2\x80\x99",
115              "'"  => "\xE2\x80\xB2",
116              "' " => "\xE2\x80\xB2",
117              "'x" => "\xE2\x80\xB2",
118              '"'  => "\xE2\x80\xB3",
119              '" ' => "\xE2\x80\xB3",
120              '"x' => "\xE2\x80\xB3"
121          );
122          $regexp = "/[0-9](?>'s|[\"']? ?x(?= ?[0-9])|[\"'])/S";
123          \preg_match_all($regexp, $this->text, $matches, \PREG_OFFSET_CAPTURE);
124          foreach ($matches[0] as $m)
125          {
126              if (\substr($m[0], -1) === 'x')
127                  $this->addTag($m[1] + \strlen($m[0]) - 1, 1, "\xC3\x97");
128              $str = \substr($m[0], 1, 2);
129              if (isset($map[$str]))
130                  $this->addTag($m[1] + 1, 1, $map[$str]);
131          }
132      }
133      protected function parseSymbolsInParentheses()
134      {
135          if (\strpos($this->text, '(') === \false)
136              return;
137          $chrs = array(
138              '(c)'  => "\xC2\xA9",
139              '(r)'  => "\xC2\xAE",
140              '(tm)' => "\xE2\x84\xA2"
141          );
142          $regexp = '/\\((?>c|r|tm)\\)/i';
143          \preg_match_all($regexp, $this->text, $matches, \PREG_OFFSET_CAPTURE);
144          foreach ($matches[0] as $m)
145              $this->addTag($m[1], \strlen($m[0]), $chrs[\strtr($m[0], 'CMRT', 'cmrt')]);
146      }
147  }